﻿@{
    Layout = "_layout";
}
@{
    ViewData["Title"] = "订单列表";
    var User = ViewBag.User as List<BuyWithoutLoseMoney.Core.Models.User>;
    var order = ViewBag.order as List<BuyWithoutLoseMoney.Core.Models.Order>;
}
@model List<BuyWithoutLoseMoney.Core.Models.Order>;

<div>
    <div class="demoTable layui-form">
        搜索订单编号：
        <div class="layui-inline">
            <input class="layui-input" name="orderid" id="orderid" autocomplete="off">
        </div>
        搜索用户：
        <div class="layui-inline">
            <input class="layui-input" name="userid" id="userid" autocomplete="off">
        </div>
       @* <div class="layui-inline">
            <label class="layui-form-label">日期范围</label>
            <div class="layui-inline" id="test6">
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" id="test-startDate-1" class="layui-input" placeholder="开始日期">
                </div>
                <div class="layui-form-mid">-</div>
                <div class="layui-input-inline">
                    <input type="text" autocomplete="off" id="test-endDate-1" class="layui-input" placeholder="结束日期">
                </div>
            </div>
        </div>*@
       @* 选择状态：
        <div class="layui-inline">
            <select name="statusId" lay-verify="required">
                @foreach (var item in order)
                {
                    <option value="@item.Id">@item.Status</option>
                }
            </select>
        </div>*@
        <div class="layui-inline">
            <button class="layui-btn" data-type="reload"><a style="color:white">搜索</a></button>
            <button class="layui-btn" id="btnAdd"><a href="/admin/order/create" style="color:white">新建</a></button>
        </div>
      
    </div>
</div>
<table class="layui-hide" id="demo" lay-filter="test"></table>
@section Scripts{
    <script>
            layui.use(['table','laydate'], function () {
            var table = layui.table;
            var laydate = layui.laydate;
                //日期范围
                laydate.render({
                    elem: '#test6'
                    //设置开始日期、日期日期的 input 选择器
                    //数组格式为 2.6.6 开始新增，之前版本直接配置 true 或任意分割字符即可
                    , range: ['#test-startDate-1', '#test-endDate-1']
                });
            //第一个实例
            table.render({
                elem: '#demo'
                , url: '/admin/order/index' //数据接口
                , page: true //开启分页
                , method: "post"
                , cols: [[ //表头
                     {type: 'checkbox', fixed: 'left'}
                    , { field: 'id', title: 'ID', width: 100, sort: true}
                    , { field: 'userName', title: '用户', width: 120 }
                    , { field: 'totalmoney', title: '商品总价', width: 160, sort: true }
                    , { field: 'status', title: '状态', width: 120 }
                    , { field: 'receivingtype', title: '收货方式', width: 120, sort: true }
                    //, { field: 'receivingaddress', title: '收货地址', width: 140, sort: true }
                    , { field: 'createtime', title: '创建时间', width: 140 }
                    , { field: 'arrivetime', title: '到货时间', width: 140 }
                    , { field: 'paymethod', title: '支付方式', width: 120 }
                    , { title: "操作", fixed: 'right', templet: " <span><a class= 'layui-btn layui-btn-primary layui-btn-xs' lay-event='detail'> 查看</a></span>" }
                    //< a lay - event='edit' class= 'layui-btn layui-btn-warm layui-btn-sm' > 编辑 < /a><a class='layui-btn layui-btn-danger layui-btn-sm' lay-event='del'>删除</a >
                   ]]
                , id: "orderList"
                , done: function () {
                    $("[data-field='status']").children().each(function () {
                        if ($(this).text() == "1") {
                            $(this).text("未付款");
                        } else if ($(this).text() == "2") {
                            $(this).text("已付款");
                        }else if ($(this).text() == "3") {
                            $(this).text("未发货");
                        }else if ($(this).text() == "4") {
                            $(this).text("已发货");
                        }
                    });
                }
            });
            //搜索功能
            var $ = layui.$, active = {
                reload: function () {
                    var orderid = $('#orderid');
                    var userid = $('#userid');
                    var statusId = $('#statusId');
                    //执行重载
                    table.reload('orderList', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: {
                            orderid: orderid.val(),
                            userid: userid.val(),
                            statusId: statusId.val(),
                        }
                    });
                }
            };
            $('.demoTable .layui-btn').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            ////单元格工具事件
            table.on('tool(test)', function (obj) { // 注：test 是 table 原始标签的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

                if (layEvent === 'del') { //删除
                    layer.confirm('确定删除吗？', function (index) {
                        $.post("/admin/order/del", { id: data.id }, function (res) {
                            if (res.isSuccess) {
                                layer.msg(res.msg, function () {
                                    table.reload("orderList");
                                });
                            } else {
                                layer.msg(res.msg);
                            }
                        });
                    });
                } else if (layEvent === "edit") {
                    var index = layer.open({
                        type: 2,
                        content: '/admin/order/edit/' + data.id,
                        area: ["40%", "100%"]
                    });
                } else if (layEvent === "detail") {
                    var index=layer.open({
                        type:2,
                        content: '/admin/Orderdetails/index/' + data.id,
                       area:["70%","40%"]
                    })
                }
            });
          
        });
    </script>
}